export interface ActionType {
  type: string;
  payload?: any;
}
export interface StateType {
  params: any;
  dropDownData: any[];
  modalData: any[];
  loading: boolean;
  total: number;
  value?: string | string[];
  [propsname: string]: any;
}
export const initState: StateType = {
  params: {
    beginIndex: 0,
    pageSize: 50,
  },
  dropDownData: [],
  modalData: [],
  loading: false,
  total: 0,
  value: undefined,
};
export function reducer(state: StateType, action: ActionType) {
  const { type, payload } = action;
  switch (type) {
    case 'save':
      return { ...state, ...payload };
    case 'saveValue': {
      return { ...state, value: payload };
    }
    case 'saveDropDownData': {
      return { ...state, dropDownData: payload };
    }
    case 'initModal': {
      return {
        ...state,
        params: {
          beginIndex: 0,
          pageSize: 50,
        },
        loading: false,
        modalData: [],
        total: 0,
      };
    }
  }
}
